if(WScript.FullName.toLowerCase().indexOf("wscript") >= 0)
{
	WScript.echo("Please use cscript.exe scripting host to run this script.");
	WScript.quit();
}

if(WScript.Arguments.length == 0)
	showUsage();

var channelNumber = WScript.Arguments(0);

var oshHost = GetObject("", "OSH.Host");
var progDvb = oshHost.GetService("Osh.ProgDvb.ProgDvbApplication");

var channel = null;
var channels = new Enumerator(progDvb.ChannelDatabase.Channels);
for(; !channels.atEnd(); channels.moveNext())
{
	if(channels.item().ChannelNumber == channelNumber)
	{
		channel = channels.item();
		break;
	}
}

if(!channel)
{
	WScript.echo("Channel not found.");
	WScript.quit();
}

WScript.echo("Channel name: " + channel.Name);
WScript.echo("Channel id  : " + channel.IdString);


var channel = progDvb.ChannelDatabase.GetChannel(channel.IdString);
if(!channel)
{
	WScript.echo("Cannot get channel by its id.");
	WScript.quit();
}


var startTime = new Date(2000, 0, 1);
var endTime = new Date(2100, 0, 1);

var epg = channel.getEpg(startTime.getVarDate(), endTime.getVarDate());
WScript.echo(epg.Events.Count + " events");

var epgEvents = new Enumerator(epg.Events);
for(; !epgEvents.atEnd(); epgEvents.moveNext())
{
	var epgEvent = epgEvents.item();

	WScript.echo("----------------------------------------");
	WScript.echo(epgEvent.Name);
	WScript.echo("Start time : " + new Date(epgEvent.StartTime).toString());
	WScript.echo("End time   : " + new Date(epgEvent.EndTime).toString());
	//WScript.echo("Language   : " + epgEvent.Language);
	WScript.echo("Description: " + epgEvent.Description);
}



function showUsage()
{
	WScript.echo("Usage: " + WScript.ScriptName + " ChannelNumber");
	WScript.quit();
}
